//
//  ViewController.m
//  test
//
//  Created by ZB on 2019/6/13.
//  Copyright © 2019 ZB. All rights reserved.
//

#import "ViewController.h"
#import "TableViewCell.h"

#define kScreenWidth CGRectGetWidth([UIScreen mainScreen].bounds)

@interface ViewController ()<UIGestureRecognizerDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *ToTrailing;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.tableView registerNib:[UINib nibWithNibName:@"TableViewCell" bundle:nil] forCellReuseIdentifier:@"TableViewCell"];
    
    UIPanGestureRecognizer *ges = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
    ges.cancelsTouchesInView = NO;
    ges.delegate = self;
    [self.view addGestureRecognizer:ges];
}

- (void)handlePan:(UIPanGestureRecognizer *)pan{
    CGPoint point = [pan translationInView:self.view];
    
//    NSLog(@"%.2f, .2%f, state:%ld",point.x, point.y, (long)pan.state);
    if (pan.state == UIGestureRecognizerStateEnded) {
        [UIView animateWithDuration:0.2 animations:^{
            self.ToTrailing.constant = -100;
            [self.view layoutIfNeeded];
        }];
    }else if (point.x < 0){
        NSLog(@"%.2f",point.x);
        CGFloat p = -point.x/2;
        p = (p > 100) ? 100 : p;
        self.ToTrailing.constant = p - 100;
    }
    NSLog(@"%.2f",point.x);
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(nonnull UIGestureRecognizer *)otherGestureRecognizer{
    return YES;//左滑时是否允许上下滑动
}

#pragma mark- table
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell"];
    return cell;
}


@end
